﻿using System;
using System.Collections.Generic;
using System.Text;
using CLoggerNamespace;

namespace HL7v_2x
{
    public class HL7SegmentACC : IHL7Segment
    {   
       #region DESARMAR SEGMENTO EN CAMPOS
        public List<HL7Fields> DesarmarSegmentoEnCampos(string strSegment)
          {
             const string strKeyReturn = "<cr>"; //FD

             List<HL7Fields> lstHL7Fields = new List<HL7Fields>();
              //EJEMPLO MENSAJE HL7
              /*
               MSH|^~\&|HIG||CPS||20050426113700||ADT^A01^ADT_A01|HIG9744495|P|2.5||||AL<cr>

              EVN|A01|20050426113700||||20050426113700|<cr>


              PID|1||163136^^^^HIG|24957389^^^^DNI|LANE^LUISA||19751128000000|F|||BLANCO ENCALADA 3422 4 C^^||||||||24957389 <cr>

              PV1|1|I|^256^|R||||||M|||A|4|A0|N||VL|H0173963||SI|||||||||||||||||||||||20050426113700 <cr>      
              
              */

              string[] strArrAux = new string[] { };
              int j = 0;  //CANTIDAD DE CAMPOS Y DE BARRAS

              strArrAux = strSegment.Split('|');
            
              foreach (string strArr in strArrAux)
              {
                  CLogger.Append("Field ARR " + j.ToString() + " : " + strArr, CLogger.INFO);
                  j++;
              }

              j--;//CANTIDAD DE |

              CLogger.Append("Cantidad de Barras" + j.ToString(), CLogger.INFO);
                
            if((strArrAux[0]!=null)&&(strArrAux[0]!=""))    // FieldSeparator_MSH = 00001,  
            {
                CLogger.Append("Field 0: " + strArrAux[0], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[0])));
                

            }
            if((strArrAux[1]!=null)&&(strArrAux[1]!=null))  // EncodingCharacters_MSH = 00002,
            {
                CLogger.Append("Field 1: "+strArrAux[1], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[1])));
            }
            if ((strArrAux[2] != "")&&(strArrAux[2]!=null)) // SendingApplication_MSH = 00003,
            {
                CLogger.Append("Field 2: " + strArrAux[2], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[2])));
            }
            if ((strArrAux[3] != "")&&(strArrAux[3]!=null)) // SendingFacility_MSH = 00004,
            {
                CLogger.Append("Field 3: "+strArrAux[3], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[3])));
            }
            if ((strArrAux[4] != "")&&(strArrAux[4]!=null)) // ReceivingFacility_MSH = 00005,
            {
                CLogger.Append("Field 4: " + strArrAux[4], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[4])));
            }
            if ((strArrAux[5] != "")&&(strArrAux[5]!=null)) // ReceivingFacility_MSH = 00005,
            {
                CLogger.Append("Field 5: " + strArrAux[5], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[5])));
            }
            if ((strArrAux[6] != "")&&(strArrAux[6]!=null)) // ReceivingApplication_MSH = 00006,
            {
                CLogger.Append("Field 6: " + strArrAux[6], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[6])));
            }
            if ((strArrAux[7] != "")&&(strArrAux[7]!=null)) // DateTimeofMessage_MSH = 00007,
            {
                CLogger.Append("Field 7: " + strArrAux[7], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[7])));
            }
            if ((strArrAux[8] != "")&&(strArrAux[8]!=null)) // Security_MSH = 00008,
            {
                CLogger.Append("Field 8: " + strArrAux[8], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[8])));
            }
            if ((strArrAux[9] != "")&&(strArrAux[9]!=null)) // MessageType_MSH = 00009,
            {
                CLogger.Append("Field 9: " + strArrAux[9], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[9])));
            }
            if ((strArrAux[10] != "")&&(strArrAux[10]!=null)) // MessageControlID_MSH = 00010,
            {
                CLogger.Append("Field 10: " + strArrAux[10], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[10])));
            }
            if ((strArrAux[11] != "")&&(strArrAux[11]!=null)) // ProcessingID_MSH = 00011,
            {
                CLogger.Append("Field 11: " + strArrAux[11], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[11])));
            }
            if ((strArrAux[12] != "")&&(strArrAux[12]!=null)) // VersionID_MSH = 00012,
            {
                CLogger.Append("Field 12: " + strArrAux[12], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[12])));
            }
            if ((strArrAux[13] != "")&&(strArrAux[13]!=null)) // SequenceNumber_MSH = 00013,
            {
                CLogger.Append("Field 13: " + strArrAux[13], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[13])));
            }
            if ((strArrAux[14] != "")&&(strArrAux[14]!=null)) //ContinuationPointer_MSH = 00014,
            {
                CLogger.Append("Field 14: " + strArrAux[14], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[14])));
            }
            if ((strArrAux[15] != "")&&(strArrAux[15]!=null)) //  AcceptAknowledgmentType_MSH = 00015,
            {
                CLogger.Append("Field 15: " + strArrAux[15], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[15])));
            }
            if ((strArrAux[16] != "")&&(strArrAux[16]!=null)) // ApplicationAknowledgmentType_MSH = 00016,
            {
                CLogger.Append("Field 16: " + strArrAux[16], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[16])));
            }
            if ((strArrAux[17] != "")&&(strArrAux[17]!=null)) //CountryCode_MSH=00017,
            {
                CLogger.Append("Field 17: " + strArrAux[17], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[17])));
            }
            if ((strArrAux[18] != "")&&(strArrAux[18]!=null)) // CharacterSet_MSH=00692,
            {
                CLogger.Append("Field 18: " + strArrAux[18], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[18])));
            }
            if ((strArrAux[19] != "")&&(strArrAux[19]!=null)) // PrincipalLanguageofMessage_MSH=00693,
            {
                CLogger.Append("Field 19: " + strArrAux[19], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[19])));
            }
            if ((strArrAux[20] != "")&&(strArrAux[20]!=null)) // AlternateCharacterSetHandlingScheme_MSH=01317,
            {
                CLogger.Append("Field 20: " + strArrAux[20], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[20])));
            }
            if ((strArrAux[21] != "")&&(strArrAux[21]!=null)) //MessageProfileIdentifier_MSH=01598,
            {
                CLogger.Append("Field 21: " + strArrAux[21], CLogger.INFO);
                System.Text.ASCIIEncoding enc = new ASCIIEncoding();  
                lstHL7Fields.Add(new HL7Fields(HL7FieldName.FieldSeparator_MSH,enc.GetBytes(strArrAux[21])));
            }
           
            return lstHL7Fields;

          }
        #endregion



        /*
        public HL7SegmentACC(): base(HL7MessageName.MessageACC)
        {

        }

        public int BuildFields(byte[] byteInputStreamParam)
        {
            throw new NotImplementedException();
        }

        public int BuildFields(byte[] byteInputStreamParam, int intOffset)
        {
            throw new NotImplementedException();
        }
         * */
    }
}
